package org.example.base;

import lombok.Data;

/**
 * @author huangy
 * @description
 * @since 2022/11/10 14:29
 **/
@Data
public class RocketMessage<T> {

    /**
     * 主题
     */
    private String topic;

    /**
     * 消息标签 区分不同的消息
     */
    private String tag;

    /**
     * 消息体
     */
    private T body;

    private RocketMessage(String topic, String tag, T body) {
        this.topic = topic;
        this.tag = tag;
        this.body = body;
    }

    private RocketMessage(String topic, String tag) {
        this(topic, tag, null);
    }

    private RocketMessage(String topic, T data) {
        this(topic, null, data);
    }

    private RocketMessage(String topic) {
        this(topic, null, null);
    }

    public static <T> RocketMessage<T> valueOf(String topic, String tag, T body) {
        return new RocketMessage<>(topic, tag, body);
    }

    public static <T> RocketMessage<T> valueOf(String topic, String tag) {
        return new RocketMessage<>(topic, tag);
    }

    public static <T> RocketMessage<T> valueOf(String topic, T data) {
        return new RocketMessage<>(topic, data);
    }

    public static <T> RocketMessage<T> valueOf(String topic) {
        return new RocketMessage<>(topic);
    }

    @Override
    public String toString() {
        return "[主题: " + topic + ", 标签: " + tag + ",消息主体: " + body.toString();
    }

}
